package com.hns.its.dao;

import com.hns.its.domain.ItsTransportDriverEntity;
import com.hns.its.persistence.jpa.GenericRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author xy
 * @date 2017-05-18 14:15
 */
@Repository
public interface IItsTransportDriverDao extends JpaRepository<ItsTransportDriverEntity, String>, JpaSpecificationExecutor<ItsTransportDriverEntity> {


	@Modifying
	@Query(value = "update  ItsTransportDriverEntity set isDelete=1 where id in (:idLst) ")
	public int deleteById(@Param(value = "idLst") String[] idLst);

	@Query(value = " FROM ItsTransportDriverEntity WHERE driveLicense =?1 and logisticId=?2")
	public ItsTransportDriverEntity findIdByLien(String name, String logisticId);

	@Query(value = " FROM ItsTransportDriverEntity WHERE accountId =?1")
	public ItsTransportDriverEntity findIdByAccountId(String accountId);

	@Query(value = " FROM ItsTransportDriverEntity WHERE driverStatusDic ='DRVS0003'")
	List<ItsTransportDriverEntity> findSickList();

    @Query(value = " FROM ItsTransportDriverEntity where name =:empName and logisticId=:logisticId")
    public ItsTransportDriverEntity findOneByName(@Param(value = "empName") String empName, @Param(value = "logisticId") String logisticId);

	@Query(value = "SELECT id FROM its_transport_driver WHERE id IN (?1) AND driver_status_dic IN ('DRVS0001','DRVS0002') ", nativeQuery = true)
	public List<String> findDriverIdInWork(List<String> dirverIds);



//    /**
//     * 根据司机状态查询司机数量
//     * 
//     * @param driverStatus
//     * @param companyId
//     * @return
//     */
//    @Query("select count(1) from ItsTransportDriverEntity a where a.driverStatusDic = ?1 and a.logisticId = ?2 ")
//    public Long countByDriverStatus(String driverStatus, String companyId);
}
